package edu.hitwh.wrapper;

import java.sql.Timestamp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Resp <T> {

    T data;
    String message;
    Boolean success;
    Integer code;
    Timestamp timestamp;

    public static <T> Resp<T> success(T data) {
        return new Resp<>(data, "", true, RespCode.SUCCESS, Timestamp.from(java.time.Instant.now()));
    }

    public static <T> Resp<T> fail(String message) {
        return new Resp<T>(null, message, false, RespCode.UNKNOWN_ERROR, Timestamp.from(java.time.Instant.now()));
    }

    public static <T> Resp<T> fail(String message, int errorCode) {
        return new Resp<T>(null, message, false, errorCode, Timestamp.from(java.time.Instant.now()));
    } 

    public static Resp<Boolean> success() {
        return new Resp<>(true, "success", true, RespCode.SUCCESS, Timestamp.from(java.time.Instant.now()));
    }
}
